/*
Copyright (C) 1997-2001 Id Software, Inc.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  

See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

// Created on 31.10.2003 by RST.
// $Id: client_persistant_t.java,v 1.7 2005/02/06 18:52:55 salomo Exp $
using System;
using Defines = Suake2.UI.Defines;
using Lib = Suake2.UI.util.Lib;
using QuakeFile = Suake2.UI.util.QuakeFile;
//UPGRADE_TODO: The type 'java.nio.ByteBuffer' could not be found. If it was not included in the conversion, there may be compiler issues. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1262'"
using ByteBuffer = java.nio.ByteBuffer;
namespace Suake2.UI.game
{
	
	public class client_persistant_t
	{
		public client_persistant_t()
		{
			InitBlock();
		}
		private void  InitBlock()
		{
			inventory = new int[Defines.MAX_ITEMS];
		}
		
		public virtual void  set_Renamed(client_persistant_t from)
		{
			
			userinfo = from.userinfo;
			netname = from.netname;
			hand = from.hand;
			connected = from.connected;
			health = from.health;
			max_health = from.max_health;
			savedFlags = from.savedFlags;
			selected_item = from.selected_item;
			Array.Copy(from.inventory, 0, inventory, 0, inventory.Length);
			max_bullets = from.max_bullets;
			max_shells = from.max_shells;
			max_rockets = from.max_rockets;
			max_grenades = from.max_grenades;
			max_cells = from.max_cells;
			max_slugs = from.max_slugs;
			weapon = from.weapon;
			lastweapon = from.lastweapon;
			power_cubes = from.power_cubes;
			score = from.score;
			game_helpchanged = from.game_helpchanged;
			helpchanged = from.helpchanged;
			spectator = from.spectator;
		}
		
		//	client data that stays across multiple level loads
		internal System.String userinfo = "";
		internal System.String netname = "";
		internal int hand;
		
		internal bool connected; // a loadgame will leave valid entities that
		// just don't have a connection yet
		
		// values saved and restored from edicts when changing levels
		internal int health;
		internal int max_health;
		internal int savedFlags;
		
		internal int selected_item;
		//UPGRADE_NOTE: The initialization of  'inventory' was moved to method 'InitBlock'. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1005'"
		internal int[] inventory;
		
		// ammo capacities
		public int max_bullets;
		public int max_shells;
		public int max_rockets;
		public int max_grenades;
		public int max_cells;
		public int max_slugs;
		//pointer
		internal gitem_t weapon;
		//pointer
		internal gitem_t lastweapon;
		internal int power_cubes; // used for tracking the cubes in coop games
		internal int score; // for calculating total unit score in coop games
		internal int game_helpchanged;
		internal int helpchanged;
		internal bool spectator; // client is a spectator
		
		/// <summary>Reads a client_persistant structure from a file. </summary>
		public virtual void  read(QuakeFile f)
		{
			
			userinfo = f.readString();
			netname = f.readString();
			
			System.IO.BinaryReader temp_BinaryReader;
			temp_BinaryReader = new System.IO.BinaryReader(f);
			temp_BinaryReader.BaseStream.Position = f.Position;
			hand = temp_BinaryReader.ReadInt32();
			
			System.IO.BinaryReader temp_BinaryReader2;
			temp_BinaryReader2 = new System.IO.BinaryReader(f);
			temp_BinaryReader2.BaseStream.Position = f.Position;
			connected = temp_BinaryReader2.ReadInt32() != 0;
			System.IO.BinaryReader temp_BinaryReader3;
			temp_BinaryReader3 = new System.IO.BinaryReader(f);
			temp_BinaryReader3.BaseStream.Position = f.Position;
			health = temp_BinaryReader3.ReadInt32();
			
			System.IO.BinaryReader temp_BinaryReader4;
			temp_BinaryReader4 = new System.IO.BinaryReader(f);
			temp_BinaryReader4.BaseStream.Position = f.Position;
			max_health = temp_BinaryReader4.ReadInt32();
			System.IO.BinaryReader temp_BinaryReader5;
			temp_BinaryReader5 = new System.IO.BinaryReader(f);
			temp_BinaryReader5.BaseStream.Position = f.Position;
			savedFlags = temp_BinaryReader5.ReadInt32();
			System.IO.BinaryReader temp_BinaryReader6;
			temp_BinaryReader6 = new System.IO.BinaryReader(f);
			temp_BinaryReader6.BaseStream.Position = f.Position;
			selected_item = temp_BinaryReader6.ReadInt32();
			
			for (int n = 0; n < Defines.MAX_ITEMS; n++)
			{
				System.IO.BinaryReader temp_BinaryReader7;
				temp_BinaryReader7 = new System.IO.BinaryReader(f);
				temp_BinaryReader7.BaseStream.Position = f.Position;
				inventory[n] = temp_BinaryReader7.ReadInt32();
			}
			
			System.IO.BinaryReader temp_BinaryReader8;
			temp_BinaryReader8 = new System.IO.BinaryReader(f);
			temp_BinaryReader8.BaseStream.Position = f.Position;
			max_bullets = temp_BinaryReader8.ReadInt32();
			System.IO.BinaryReader temp_BinaryReader9;
			temp_BinaryReader9 = new System.IO.BinaryReader(f);
			temp_BinaryReader9.BaseStream.Position = f.Position;
			max_shells = temp_BinaryReader9.ReadInt32();
			System.IO.BinaryReader temp_BinaryReader10;
			temp_BinaryReader10 = new System.IO.BinaryReader(f);
			temp_BinaryReader10.BaseStream.Position = f.Position;
			max_rockets = temp_BinaryReader10.ReadInt32();
			System.IO.BinaryReader temp_BinaryReader11;
			temp_BinaryReader11 = new System.IO.BinaryReader(f);
			temp_BinaryReader11.BaseStream.Position = f.Position;
			max_grenades = temp_BinaryReader11.ReadInt32();
			System.IO.BinaryReader temp_BinaryReader12;
			temp_BinaryReader12 = new System.IO.BinaryReader(f);
			temp_BinaryReader12.BaseStream.Position = f.Position;
			max_cells = temp_BinaryReader12.ReadInt32();
			System.IO.BinaryReader temp_BinaryReader13;
			temp_BinaryReader13 = new System.IO.BinaryReader(f);
			temp_BinaryReader13.BaseStream.Position = f.Position;
			max_slugs = temp_BinaryReader13.ReadInt32();
			
			weapon = f.readItem();
			lastweapon = f.readItem();
			System.IO.BinaryReader temp_BinaryReader14;
			temp_BinaryReader14 = new System.IO.BinaryReader(f);
			temp_BinaryReader14.BaseStream.Position = f.Position;
			power_cubes = temp_BinaryReader14.ReadInt32();
			System.IO.BinaryReader temp_BinaryReader15;
			temp_BinaryReader15 = new System.IO.BinaryReader(f);
			temp_BinaryReader15.BaseStream.Position = f.Position;
			score = temp_BinaryReader15.ReadInt32();
			
			System.IO.BinaryReader temp_BinaryReader16;
			temp_BinaryReader16 = new System.IO.BinaryReader(f);
			temp_BinaryReader16.BaseStream.Position = f.Position;
			game_helpchanged = temp_BinaryReader16.ReadInt32();
			System.IO.BinaryReader temp_BinaryReader17;
			temp_BinaryReader17 = new System.IO.BinaryReader(f);
			temp_BinaryReader17.BaseStream.Position = f.Position;
			helpchanged = temp_BinaryReader17.ReadInt32();
			System.IO.BinaryReader temp_BinaryReader18;
			temp_BinaryReader18 = new System.IO.BinaryReader(f);
			temp_BinaryReader18.BaseStream.Position = f.Position;
			spectator = temp_BinaryReader18.ReadInt32() != 0;
		}
		
		/// <summary>Writes a client_persistant structure to a file. </summary>
		public virtual void  write(QuakeFile f)
		{
			// client persistant_t
			f.writeString(userinfo);
			f.writeString(netname);
			
			System.IO.BinaryWriter temp_BinaryWriter;
			temp_BinaryWriter = new System.IO.BinaryWriter(f);
			temp_BinaryWriter.Write((System.Int32) hand);
			
			System.IO.BinaryWriter temp_BinaryWriter2;
			temp_BinaryWriter2 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter2.Write((System.Int32) (connected?1:0));
			System.IO.BinaryWriter temp_BinaryWriter3;
			temp_BinaryWriter3 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter3.Write((System.Int32) health);
			
			System.IO.BinaryWriter temp_BinaryWriter4;
			temp_BinaryWriter4 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter4.Write((System.Int32) max_health);
			System.IO.BinaryWriter temp_BinaryWriter5;
			temp_BinaryWriter5 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter5.Write((System.Int32) savedFlags);
			System.IO.BinaryWriter temp_BinaryWriter6;
			temp_BinaryWriter6 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter6.Write((System.Int32) selected_item);
			
			for (int n = 0; n < Defines.MAX_ITEMS; n++)
			{
				System.IO.BinaryWriter temp_BinaryWriter7;
				temp_BinaryWriter7 = new System.IO.BinaryWriter(f);
				temp_BinaryWriter7.Write((System.Int32) inventory[n]);
			}
			
			System.IO.BinaryWriter temp_BinaryWriter8;
			temp_BinaryWriter8 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter8.Write((System.Int32) max_bullets);
			System.IO.BinaryWriter temp_BinaryWriter9;
			temp_BinaryWriter9 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter9.Write((System.Int32) max_shells);
			System.IO.BinaryWriter temp_BinaryWriter10;
			temp_BinaryWriter10 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter10.Write((System.Int32) max_rockets);
			System.IO.BinaryWriter temp_BinaryWriter11;
			temp_BinaryWriter11 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter11.Write((System.Int32) max_grenades);
			System.IO.BinaryWriter temp_BinaryWriter12;
			temp_BinaryWriter12 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter12.Write((System.Int32) max_cells);
			System.IO.BinaryWriter temp_BinaryWriter13;
			temp_BinaryWriter13 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter13.Write((System.Int32) max_slugs);
			
			f.writeItem(weapon);
			f.writeItem(lastweapon);
			System.IO.BinaryWriter temp_BinaryWriter14;
			temp_BinaryWriter14 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter14.Write((System.Int32) power_cubes);
			System.IO.BinaryWriter temp_BinaryWriter15;
			temp_BinaryWriter15 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter15.Write((System.Int32) score);
			
			System.IO.BinaryWriter temp_BinaryWriter16;
			temp_BinaryWriter16 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter16.Write((System.Int32) game_helpchanged);
			System.IO.BinaryWriter temp_BinaryWriter17;
			temp_BinaryWriter17 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter17.Write((System.Int32) helpchanged);
			System.IO.BinaryWriter temp_BinaryWriter18;
			temp_BinaryWriter18 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter18.Write((System.Int32) (spectator?1:0));
		}
	}
}